package exam;

import java.util.Scanner;

/**
 * @author blh
 * @date 2024年06月28日 10:58
 */

public class xiaomi2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int t = 0; t < T; t++) {
            int n = in.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            for (int i = 0; i < n; i++) {
                b[i] = in.nextInt();
            }
            // 升序或者降序
            boolean sign = false;

            // 升序的情况
            int minPre = Math.min(a[0], b[0]);
            for (int i = 1; i < n; i++) {
                int small = Math.min(a[i], b[i]);
                int big = Math.max(a[i], b[i]);
                if (big<minPre){
                    break;
                } else {
                    minPre = small>=minPre?small:big;
                }
                if (i==n-1){
                    sign = true;
                }
            }

            // 降序的情况
            int maxPre = Math.max(a[0], b[0]);
            for (int i = 1; i < n; i++) {
                int small = Math.min(a[i], b[i]);
                int big = Math.max(a[i], b[i]);
                if (small>maxPre){
                    break;
                } else {
                    maxPre = big<=maxPre?big:small;
                }
                if (i==n-1){
                    sign = true;
                }
            }

            if (sign) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}
